package utilities;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

/**
 * The Class FormatDouble.
 * 
 * @author Nils Berlijn
 * @author Henderikus Harms
 * @version 1.0
 * @since June 1, 2014
 */
public final class FormatDouble 
{
	
	/**
	 * Format.
	 *
	 * @param oldDouble the old double
	 * @param decimals the decimals
	 * @return the string
	 */
	public static String format(Double oldDouble, Integer decimals)	
	{
		Locale locale  = new Locale("en", "UK");
		String pattern = "###.#";
		
		if(decimals.equals(2))
			pattern = "###.##";

		DecimalFormat decimalFormat = (DecimalFormat)NumberFormat.getNumberInstance(locale);
		decimalFormat.applyPattern(pattern);	
		
		String newDouble = decimalFormat.format(oldDouble);
		
		return newDouble;
	}
}